/*
 * @Author: 清香白莲 1243327527@qq.com
 * @Date: 2023-09-12 14:42:02
 * @LastEditors: 清香白莲 1243327527@qq.com
 * @LastEditTime: 2023-09-21 11:33:10
 * @FilePath: /shang_study/src/store/detail.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { reqGetGoodsDetail, reqPostAddCar } from "@/api";
import { getUUID } from "@/utils/uuid_token";

export default {
    namespaced: true,
    actions: {
        async getGoodsDetail(content, skuId) {
            let result = await reqGetGoodsDetail(skuId);
            if (result.code == 200) {
                content.commit('GETGOODSDETAIL', result.data);
            }else {
                content.commit('GETGOODSDETAIL', {});
            }
        },
        async postAddToCar(content, {skuId, skuNum}) {
            let result = await reqPostAddCar(skuId, skuNum);
            console.log(result);
            if (result.code == 200) {
                return 'ok';
            }else {
                return Promise.reject(new Error('faile'));
            }
        }
    },
    mutations: {
        GETGOODSDETAIL(state, goodsDetail) {
            state.goodsDetail = goodsDetail;
        },
    },
    state: {
        goodsDetail: {},
        // 游客临时身份
        uuid_token: getUUID(),
    },
    getters: {
        categoryView(state) {
            return state.goodsDetail.categoryView || {};
        },
        spuSaleAttrList(state) {
            return state.goodsDetail.spuSaleAttrList || [];
        },
        skuInfo(state) {
            return state.goodsDetail.skuInfo || {};
        },
        spuSaleAttrList(state) {
            return state.goodsDetail.spuSaleAttrList || [];
        }
    },
}